package com.rpa.server.servicerpaserver.expose.controller;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.rpa.secure.servicerpasecure.common.result.Result;
import com.rpa.server.servicerpaserver.crawler.entity.Stu;
import com.rpa.server.servicerpaserver.crawler.entity.dto.CrawlerDto;
import com.rpa.server.servicerpaserver.crawler.service.StuService;
import com.rpa.server.servicerpaserver.util.NameUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @className: StuController
 * @author: lzt
 * @date: 2025/2/18 10:56
 * @Version: 1.0
 * @description:
 */
@RestController
@RequestMapping("/api/stu")
@Slf4j
@Tag(name = "本系统教务系统信息相关接口", description = "StuController")
public class StuController {
    @Autowired
    private StuService stuService;

    @PostMapping("/getStuEnum")
    @Operation(summary = "获取回填枚举信息",description = "getStuEnum")
    public Result<List<Map<String,Object>>> getStuEnum(@RequestBody CrawlerDto crawlerDto){
        LambdaQueryWrapper<Stu> eq = new LambdaQueryWrapper<Stu>()
                .eq(Stu::getAccountId, crawlerDto.getAccountId());
        List<Map<String, Object>> list = stuService.listMaps(eq);
        List<Map<String, Object>> camelCaseActiveList = list.stream()
                .map(NameUtil::underlineToCamelCase)
                .collect(Collectors.toList());
        List<Map<String, Object>> collect=null;
        if (list.size() > 0) {
             collect = camelCaseActiveList.stream().map(map -> {
                 String idStr = MapUtil.getStr(map, "id");
                 if (idStr != null) {
                     map.put("id", idStr);
                 }
                String stuYear = MapUtil.getStr(map, "stuYear", "");
                String courseName = MapUtil.getStr(map, "courseName", "");
                String clazzName = MapUtil.getStr(map, "clazzName", "");
                map.put("value", stuYear + "--" + courseName + "--" + clazzName);
                return map;
            }).collect(Collectors.toList());
        }
        return Result.success(collect);
    }
}
